
var yoFields = "yoKey,yoStatus,yoAlias,yoMatingType,yoMatingTypeMethod,yoIsSC,yoIsSCMethod,yoPloidy,yoPloidyMethod,yoPloidyNotes,yoGenotype,yoParent,yoProgenitor,yoSiblings,yoContinent,yoCountry,yoLocale,yoGeoDate,yoEnvSource,yoGeoNotes,yoEnvNotes,yoBoxNumber,yoIsbNumber,yoPosition,yoDateFrozen,yoContributor,yoSavedBy,yoQCStatus,yoQCReason,yoQCNotes,yoMTA,yoComments";
var yadFields = "yadKey,yadAlias,yadMatingType,yadSource,yadParent,yadContributor,yadGenotype,yadBoxNumber,yadIsbNumber,yadPosition,yadDateFrozen,yadComments";
var ypgFields =  "ypgKey,ypgBoxNumber,ypgCrossingRef,ypgMatingType,ypgGenotype,ypgParentA,ypgParentAlpha,ypgAlias,ypgTetrad,ypgStatus,ypgPosition,ypgComments,ypgDateFrozen,ypgSiblings";
var ycrFields = "ycrKey,ycrAlias,ycrType,ycrParentA,ycrParentAlpha,ycrProgenyCt,ycrProgenyRange,ycrTetradCt,ycrDate,ycrSnps,ycrSnpDupes,ycrPlates,ycrNotes,ycrIGV,ycrYCGSKeys,ycrYCGSKey1,ycrYCGSKey2";

function getSolrYoUrl(searchTerm, maxresults) {
    return "/solr/select/?q=" + "(yoFields:SPS2 AND yoFields:wine)".replace(" ", "%20") + "&wt=json&rows=" + maxresults + "&fl=yoKey," +
           "yoStatus,yoAlias,yoMatingType,yoMatingTypeMethod,yoIsSC,yoIsSCMethod,yoPloidy," +
           "yoPloidyMethod,yoPloidyNotes,yoGenotype,yoParent,yoProgenitor,yoSiblings," +
           "yoContinent,yoCountry,yoLocale,yoGeoDate,yoEnvSource,yoGeoNotes,yoEnvNotes," +
           "yoBoxNumber,yoIsbNumber,yoPosition,yoDateFrozen,yoContributor,yoSavedBy," +
           "yoQCStatus,yoQCReason,yoQCNotes,yoMTA,yoComments";
}

function validateCreateWildStrain(strainType) {
    return true;
}

function isNumeric(input)
{
    return (input - 0) == input && input.length > 0;
}

function getSampleSearchOptionsArray() {
    return [
        ['all', 'All'],
        ['strainName', 'strainName'],
        ['alias', 'alias'],
        ['status', 'status'],
        ['isSC', 'isSC'],
        ['matingType', 'matingType'],
        ['genotype', 'genotype'],
        ['contributor', 'contributor'],
        ['savedBy', 'savedBy'],
        ['strainSource', 'strainSource'],
        ['continent', 'continent'],
        ['country', 'country'],
        ['locale', 'locale'],
        ['environmentSource', 'environmentSource'],
        ['environmentNotes', 'environmentNotes'],
        ['strainProgenitor', 'strainProgenitor'],
        ['strainParents', 'strainParents'],
        ['boxNumber', 'boxNumber'],
        ['isbBoxNumber', 'isbBoxNumber'],
        ['position', 'position'],
        ['dateFrozen', 'dateFrozen'],
        ['mta', 'mta'],
        ['comments', 'comments']
    ];
}

/*
 function translateStrainResultToJson(jsonSearchArray) {
 var jsonObj = [];
 var yoKey = jsonSearchArray.name;
 jsonObj[0] = yoKey.substring(3, yoKey.length);
 jsonObj[1] = jsonSearchArray.name;
 jsonObj[2] = jsonSearchArray.alias;
 jsonObj[3] = jsonSearchArray.status;
 jsonObj[4] = jsonSearchArray.matingType;
 jsonObj[5] = jsonSearchArray.genotype;
 jsonObj[6] = jsonSearchArray.strainSource;
 jsonObj[7] = jsonSearchArray.strainParents;
 jsonObj[8] = jsonSearchArray.boxNumber;
 jsonObj[9] = jsonSearchArray.dateFrozen;
 jsonObj[10] = jsonSearchArray.contributor;
 jsonObj[11] = jsonSearchArray.comments;
 jsonObj[12] = jsonSearchArray.isSC;
 jsonObj[13] = jsonSearchArray.position;
 jsonObj[14] = jsonSearchArray.strainProgenitor;
 jsonObj[15] = jsonSearchArray.continent;
 jsonObj[16] = jsonSearchArray.country;
 jsonObj[17] = jsonSearchArray.locale;
 jsonObj[18] = jsonSearchArray.environmentSource;
 jsonObj[19] = jsonSearchArray.environmentNotes;
 jsonObj[20] = jsonSearchArray.matingTypeDetermination;
 jsonObj[21] = jsonSearchArray.ploidy;
 jsonObj[22] = jsonSearchArray.ploidyDetermination;
 jsonObj[23] = jsonSearchArray.qcFailure;
 jsonObj[24] = jsonSearchArray.qcFailureReason;
 jsonObj[25] = jsonSearchArray.qcNotes;
 jsonObj[26] = jsonSearchArray.savedBy;
 jsonObj[27] = jsonSearchArray.siblings;
 jsonObj[28] = jsonSearchArray.mta;
 jsonObj[29] = jsonSearchArray.ceresiaeDetermination;
 jsonObj[30] = jsonSearchArray.ploidyNotes;
 jsonObj[31] = jsonSearchArray.isbBoxNumber;
 jsonObj[32] = jsonSearchArray.geographyDate;
 return jsonObj;
 }
 */

function translateYOSolrToJson(jsonSearchArray) {
    var jsonObj = [];
    var yoKey = jsonSearchArray.yoKey;
    jsonObj[0] = yoKey.substring(2, yoKey.length);
    jsonObj[1] = yoKey;
    jsonObj[2] = jsonSearchArray.yoAlias;
    jsonObj[3] = jsonSearchArray.yoStatus;
    jsonObj[4] = jsonSearchArray.yoMatingType;
    jsonObj[5] = jsonSearchArray.yoGenotype;
    jsonObj[6] = jsonSearchArray.yoGeoNotes;
    jsonObj[7] = jsonSearchArray.yoParent;
    jsonObj[8] = jsonSearchArray.yoBoxNumber;
    jsonObj[9] = jsonSearchArray.yoDateFrozen;
    jsonObj[10] = jsonSearchArray.yoContributor;
    jsonObj[11] = jsonSearchArray.yoComments;
    jsonObj[12] = jsonSearchArray.yoIsSC;
    jsonObj[13] = jsonSearchArray.yoPosition;
    jsonObj[14] = jsonSearchArray.yoProgenitor;
    jsonObj[15] = jsonSearchArray.yoContinent;
    jsonObj[16] = jsonSearchArray.yoCountry;
    jsonObj[17] = jsonSearchArray.yoLocale;
    jsonObj[18] = jsonSearchArray.yoEnvSource;
    jsonObj[19] = jsonSearchArray.yoEnvNotes;
    jsonObj[20] = jsonSearchArray.yoMatingTypeMethod;
    jsonObj[21] = jsonSearchArray.yoPloidy;
    jsonObj[22] = jsonSearchArray.yoPloidyMethod;
    jsonObj[23] = jsonSearchArray.yoQCStatus;
    jsonObj[24] = jsonSearchArray.yoQCReason;
    jsonObj[25] = jsonSearchArray.yoQCNotes;
    jsonObj[26] = jsonSearchArray.yoSavedBy;
    jsonObj[27] = jsonSearchArray.yoSiblings;
    jsonObj[28] = jsonSearchArray.yoMTA;
    jsonObj[29] = jsonSearchArray.yoIsSCMethod;
    jsonObj[30] = jsonSearchArray.yoPloidyNotes;
    jsonObj[31] = jsonSearchArray.yoIsbNumber;
    jsonObj[32] = jsonSearchArray.yoGeoDate;
    return jsonObj;
}

var yoSolrTranslator = function(jsonSearchArray) {
    var jsonObj = [];
    var yoKey = jsonSearchArray.yoKey;
    jsonObj[0] = yoKey.substring(2, yoKey.length);
    jsonObj[1] = yoKey;
    jsonObj[2] = jsonSearchArray.yoAlias;
    jsonObj[3] = jsonSearchArray.yoStatus;
    jsonObj[4] = jsonSearchArray.yoMatingType;
    jsonObj[5] = jsonSearchArray.yoGenotype;
    jsonObj[6] = jsonSearchArray.yoGeoNotes;
    jsonObj[7] = jsonSearchArray.yoParent;
    jsonObj[8] = jsonSearchArray.yoBoxNumber;
    jsonObj[9] = jsonSearchArray.yoDateFrozen;
    jsonObj[10] = jsonSearchArray.yoContributor;
    jsonObj[11] = jsonSearchArray.yoComments;
    jsonObj[12] = jsonSearchArray.yoIsSC;
    jsonObj[13] = jsonSearchArray.yoPosition;
    jsonObj[14] = jsonSearchArray.yoProgenitor;
    jsonObj[15] = jsonSearchArray.yoContinent;
    jsonObj[16] = jsonSearchArray.yoCountry;
    jsonObj[17] = jsonSearchArray.yoLocale;
    jsonObj[18] = jsonSearchArray.yoEnvSource;
    jsonObj[19] = jsonSearchArray.yoEnvNotes;
    jsonObj[20] = jsonSearchArray.yoMatingTypeMethod;
    jsonObj[21] = jsonSearchArray.yoPloidy;
    jsonObj[22] = jsonSearchArray.yoPloidyMethod;
    jsonObj[23] = jsonSearchArray.yoQCStatus;
    jsonObj[24] = jsonSearchArray.yoQCReason;
    jsonObj[25] = jsonSearchArray.yoQCNotes;
    jsonObj[26] = jsonSearchArray.yoSavedBy;
    jsonObj[27] = jsonSearchArray.yoSiblings;
    jsonObj[28] = jsonSearchArray.yoMTA;
    jsonObj[29] = jsonSearchArray.yoIsSCMethod;
    jsonObj[30] = jsonSearchArray.yoPloidyNotes;
    jsonObj[31] = jsonSearchArray.yoIsbNumber;
    jsonObj[32] = jsonSearchArray.yoGeoDate;
    return jsonObj;
};


function getSearchYadUrl(strainType, freeSearchOp, matchingAllTerms, matchingSearchHash) {
    return "/addama-rest/dudley-sample/path/datasource/" + strainType + "/search?" + freeSearchOp + matchingAllTerms +
           "&PROJECTION=alias" +
           "&PROJECTION=genotype" +
           "&PROJECTION=strainSource" +
           "&PROJECTION=strainParents" +
           "&PROJECTION=strainProgenitor" +
           "&PROJECTION=contributor" +
           "&PROJECTION=matingType" +
           "&PROJECTION=boxNumber" +
           "&PROJECTION=isbBoxNumber" +
           "&PROJECTION=dateFrozen" +
           "&PROJECTION=comments" +
           "&PROJECTION=proteomics" +
           "&PROJECTION=rna" +
           "&PROJECTION=sequencing" +
           "&PROJECTION=imaging" +
           "&PROJECTION=isSC" +
           "&PROJECTION=position" +
           matchingSearchHash;
}

function translateYADResultToJson(jsonSearchArray) {
    var jsonObj = [];
    var yadKey = jsonSearchArray.name;
    jsonObj[0] = yadKey.substring(3, yadKey.length);
    jsonObj[1] = jsonSearchArray.name;
    jsonObj[2] = jsonSearchArray.alias;
    jsonObj[3] = jsonSearchArray.status;
    jsonObj[4] = jsonSearchArray.matingType;
    jsonObj[5] = jsonSearchArray.genotype;
    jsonObj[6] = jsonSearchArray.strainSource;
    jsonObj[7] = jsonSearchArray.strainParents;
    jsonObj[8] = jsonSearchArray.boxNumber;
    jsonObj[9] = jsonSearchArray.dateFrozen;
    jsonObj[10] = jsonSearchArray.contributor;
    jsonObj[11] = jsonSearchArray.comments;
    jsonObj[12] = jsonSearchArray.position;
    jsonObj[13] = jsonSearchArray.isbBoxNumber;
    return jsonObj;
}

function translateYADSolrToJson(jsonSearchArray) {
    var jsonObj = [];
    var yadKey = jsonSearchArray.yadKey
    jsonObj[0] = yadKey.substring(3, yadKey.length);
    jsonObj[1] = yadKey;
    jsonObj[2] = jsonSearchArray.yadAlias;
    jsonObj[3] = jsonSearchArray.yadStatus;
    jsonObj[4] = jsonSearchArray.yadMatingType;
    jsonObj[5] = jsonSearchArray.yadGenotype;
    jsonObj[6] = jsonSearchArray.yadSource;
    jsonObj[7] = jsonSearchArray.yadParent;
    jsonObj[8] = jsonSearchArray.yadBoxNumber;
    jsonObj[9] = jsonSearchArray.yadDateFrozen;
    jsonObj[10] = jsonSearchArray.yadContributor;
    jsonObj[11] = jsonSearchArray.yadComments;
    jsonObj[12] = jsonSearchArray.yadPosition;
    jsonObj[13] = jsonSearchArray.yadIsbNumber;
    return jsonObj;
}

var yadSolrTranslator = function(jsonSearchArray) {
    var jsonObj = [];
    var yadKey = jsonSearchArray.yadKey
    jsonObj[0] = yadKey.substring(3, yadKey.length);
    jsonObj[1] = yadKey;
    jsonObj[2] = jsonSearchArray.yadAlias;
    jsonObj[3] = jsonSearchArray.yadStatus;
    jsonObj[4] = jsonSearchArray.yadMatingType;
    jsonObj[5] = jsonSearchArray.yadGenotype;
    jsonObj[6] = jsonSearchArray.yadSource;
    jsonObj[7] = jsonSearchArray.yadParent;
    jsonObj[8] = jsonSearchArray.yadBoxNumber;
    jsonObj[9] = jsonSearchArray.yadDateFrozen;
    jsonObj[10] = jsonSearchArray.yadContributor;
    jsonObj[11] = jsonSearchArray.yadComments;
    jsonObj[12] = jsonSearchArray.yadPosition;
    jsonObj[13] = jsonSearchArray.yadIsbNumber;
    return jsonObj;
};

function getYADPagingColumns() {
    return [
        {
            name: 'indexNum',
            type: 'float'
        },
        {
            name: 'name'
        },
        {
            name: 'alias'
        },
        {
            name: 'status'
        },
        {
            name: 'matingType'
        },
        {
            name: 'genotype'
        },
        {
            name: 'strainSource'
        },
        {
            name: 'strainParents'
        },
        {
            name: 'boxNumber'
        },
        {
            name: 'dateFrozen'
        },
        {
            name: 'contributor'
        },
        {
            name: 'comments'
        },
        {
            name: 'position'
        },
        {
            name: 'isbBoxNumber'
        }
    ];
}

function getYADColumnHeaders() {
    return [
        {
            header: 'Index',
            width: 50,
            sortable: true,
            dataIndex: 'indexNum'
        },
        {
            id:'name',
            header: 'Name',
            width: 60,
            sortable: true,
            dataIndex: 'name'
        },
        {
            header: 'Alias',
            width: 125,
            sortable: true,
            dataIndex: 'alias'
        },
        {
            header: 'Mating Type',
            width: 80,
            sortable: true,
            dataIndex: 'matingType'
        },
        {
            header: 'Genotype',
            width: 125,
            sortable: true,
            dataIndex: 'genotype'
        },
        {
            header: 'Source',
            width: 75,
            hidden: true,
            sortable: true,
            dataIndex: 'strainSource'
        },
        {
            header: 'Parent',
            width: 75,
            sortable: true,
            dataIndex: 'strainParents'
        },
        {
            header: 'BoxNum',
            width: 50,
            sortable: true,
            dataIndex: 'boxNumber'
        },
        {
            header: 'Position',
            width:50,
            sortable: true,
            dataIndex: 'position'
        },
        {
            header: 'DateFrozen',
            width: 80,
            sortable: true,
            //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
            dataIndex: 'dateFrozen'
        },
        {
            header: 'Contributor',
            hidden: true,
            dataIndex: 'contributor'
        },
        {
            header: 'Comments',
            hidden: true,
            dataIndex: 'comments'
        }
    ];
}


function getPagingColumns() {
    return [
        {
            name: 'indexNum',
            type: 'float'
        },
        {
            name: 'name'
        },
        {
            name: 'alias'
        },
        {
            name: 'status'
        },
        {
            name: 'matingType'
        },
        {
            name: 'genotype'
        },
        {
            name: 'strainSource'
        },
        {
            name: 'strainParents'
        },
        {
            name: 'boxNumber'
        },
        {
            name: 'dateFrozen'
        },
        {
            name: 'contributor'
        },
        {
            name: 'comments'
        },
        {
            name: 'isSC'
        },
        {
            name: 'position'
        },
        {
            name: 'strainProgenitor'
        },
        {
            name: 'continent'
        },
        {
            name: 'country'
        },
        {
            name: 'locale'
        },
        {
            name: 'environmentSource'
        },
        {
            name: 'environmentNotes'
        },
        {
            name: 'matingTypeDetermination'
        },
        {
            name: 'ploidy'
        },
        {
            name: 'ploidyDetermination'
        },
        {
            name: 'qcFailure'
        },
        {
            name: 'qcFailureReason'
        },
        {
            name: 'qcNotes'
        },
        {
            name: 'savedBy'
        },
        {
            name: 'siblings'
        },
        {
            name: 'mta'
        },
        {
            name: 'ceresiaeDetermination'
        },
        {
            name: 'ploidyNotes'
        },
        {
            name: 'isbBoxNumber'
        },
        {
            name: 'geographyDate'
        }
    ];
}

function initStrainJson(strainHash) {
    strainHash.alias = undefined;
    strainHash.matingType = 'Undetermined';
    strainHash.genotype = undefined;
    strainHash.strainSource = undefined;
    strainHash.strainParents = undefined;
    strainHash.strainProgenitor = "";
    strainHash.contributor = undefined;
    strainHash.dateFrozen = undefined;
    strainHash.comments = "";
    strainHash.isSC = "Unknown";
    strainHash.status = "Undetermined";
    strainHash.geography = "";
    strainHash.continent = "Unknown";
    strainHash.country = "Unknown";
    strainHash.locale = "";

}

function getStrainSearchColumnHeaders(strainType) {
    var hideStatus = false;
    if (strainType == "YAD") {
        hideStatus = true;
    }
    return [
        {
            header: 'Index',
            width: 50,
            sortable: true,
            dataIndex: 'indexNum'
        },
        {
            id:'name',
            header: 'Name',
            width: 60,
            sortable: true,
            dataIndex: 'name'
        },
        {
            header: 'Alias',
            width: 125,
            sortable: true,
            dataIndex: 'alias'
        },
        {
            header: 'Status',
            width: 100,
            sortable: true,
            hidden: hideStatus,
            dataIndex: 'status'
        },
        {
            header: 'Mating Type',
            width: 80,
            sortable: true,
            dataIndex: 'matingType'
        },
        {
            header: 'Genotype',
            width: 125,
            sortable: true,
            dataIndex: 'genotype'
        },
        {
            header: 'Source',
            width: 75,
            hidden: true,
            sortable: true,
            dataIndex: 'strainSource'
        },
        {
            header: 'Parent',
            width: 75,
            sortable: true,
            dataIndex: 'strainParents'
        },
        {
            header: 'BoxNum',
            width: 50,
            sortable: true,
            dataIndex: 'boxNumber'
        },
        {
            header: 'Position',
            width:50,
            sortable: true,
            dataIndex: 'position'
        },
        {
            header: 'DateFrozen',
            width: 80,
            sortable: true,
            //renderer: Ext.util.Format.dateRenderer('m/d/Y'),
            dataIndex: 'dateFrozen'
        },
        {
            header: 'Contributor',
            hidden: true,
            dataIndex: 'contributor'
        },
        {
            header: 'Comments',
            hidden: true,
            dataIndex: 'comments'
        },
        {
            header: 'strainProgenitor',
            hidden: true,
            dataIndex: 'strainProgenitor'
        },
        {
            header: 'isbBoxNumber',
            hidden: true,
            dataIndex: 'isbBoxNumber'
        }
    ];
}

function populateStrainJson(strainHash, g) {
    var selectedData = g.getSelectionModel().getSelected().data;
    strainHash.name = selectedData.name;
    strainHash.alias = selectedData.alias;
    strainHash.status = selectedData.status;
    strainHash.matingType = selectedData.matingType;
    strainHash.matingTypeDetermination = selectedData.matingTypeDetermination;
    strainHash.ploidy = selectedData.ploidy;
    strainHash.ploidyDetermination = selectedData.ploidyDetermination;
    strainHash.genotype = selectedData.genotype;
    strainHash.strainSource = selectedData.strainSource;
    strainHash.contributor = selectedData.contributor;
    strainHash.strainParents = selectedData.strainParents;
    strainHash.boxNumber = selectedData.boxNumber;
    strainHash.dateFrozen = selectedData.dateFrozen;
    strainHash.comments = selectedData.comments;
    strainHash.proteomicsData = selectedData.proteomicsData;
    strainHash.rnaData = selectedData.rnaData;
    strainHash.sequencingData = selectedData.sequencingData;
    strainHash.imaging = selectedData.imaging;
    strainHash.isSC = selectedData.isSC;
    strainHash.position = selectedData.position;
    strainHash.continent = selectedData.continent;
    strainHash.country = selectedData.country;
    strainHash.locale = selectedData.locale;
    strainHash.geographyNotes = selectedData.geographyNotes;
    strainHash.environmentSource = selectedData.environmentSource;
    strainHash.environmentNotes = selectedData.environmentNotes;
    strainHash.strainProgenitor = selectedData.strainProgenitor;
    strainHash.qcFailure = selectedData.qcFailure;
    strainHash.qcFailureReason = selectedData.qcFailureReason;
    strainHash.qcNotes = selectedData.qcNotes;
    strainHash.savedBy = selectedData.savedBy;
    strainHash.siblings = selectedData.siblings;
    strainHash.mta = selectedData.mta;
    strainHash.ceresiaeDetermination = selectedData.ceresiaeDetermination;
    strainHash.ploidyNotes = selectedData.ploidyNotes;
    strainHash.isbBoxNumber = selectedData.isbBoxNumber;
    strainHash.geographyDate = selectedData.geographyDate;
}

function populateSingleStrainViaSearch(strainHash, rec) {
    strainHash.name = rec.yoKey;
    strainHash.alias = rec.yoAlias;
    strainHash.status = rec.yoStatus;
    strainHash.matingType = rec.yoMatingType;
    strainHash.genotype = rec.yoGenotype;
    //strainHash.strainSource = rec.yoEnvNotes;
    strainHash.strainParents = rec.yoParent;
    strainHash.boxNumber = rec.yoBoxNumber;
    strainHash.dateFrozen = rec.yoDateFrozen;
    strainHash.contributor = rec.yoContributor;
    strainHash.comments = rec.yoComments;
    strainHash.isSC = rec.yoIsSC;
    strainHash.position = rec.yoPosition;
    strainHash.strainProgenitor = rec.yoProgenitor;
    strainHash.continent = rec.yoContinent;
    strainHash.country = rec.yoCountry;
    strainHash.locale = rec.yoLocale;
    strainHash.environmentSource = rec.yoEnvSource;
    strainHash.environmentNotes = rec.yoEnvNotes;
    strainHash.matingTypeDetermination = rec.yoMatingTypeMethod;
    strainHash.ploidy = rec.yoPloidy;
    strainHash.ploidyDetermination = rec.yoPloidyMethod;
    strainHash.qcFailure = rec.yoQCStatus;
    strainHash.qcFailureReason = rec.yoQCReason;
    strainHash.qcNotes = rec.yoQCNotes;
    strainHash.savedBy = rec.yoSavedBy;
    strainHash.siblings = rec.yoSiblings;
    strainHash.mta = rec.yoMTA;
    strainHash.ceresiaeDetermination = rec.yoIsSCMethod;
    strainHash.ploidyNotes = rec.yoPloidyNotes;
    strainHash.isbBoxNumber = rec.yoIsbNumber;
    strainHash.geographyDate = rec.yoGeoDate;
}

function populateSingleStrainViaArray(strainHash, rec) {

    strainHash.name = rec[1];
    strainHash.alias = rec[2]
    strainHash.status = rec[3];
    strainHash.matingType = rec[4];
    strainHash.genotype = rec[5];
    strainHash.strainParents = rec[7];
    strainHash.boxNumber = rec[8];
    strainHash.dateFrozen = rec[9];
    strainHash.contributor = rec[10];
    strainHash.comments = rec[11];
    strainHash.isSC = rec[12];
    strainHash.position = rec[13];
    strainHash.strainProgenitor = rec[14];
    strainHash.continent = rec[15];
    strainHash.country = rec[16];
    strainHash.locale = rec[17];
    strainHash.environmentSource = rec[18];
    strainHash.environmentNotes = rec[19];
    strainHash.matingTypeDetermination = rec[20];
    strainHash.ploidy = rec[21];
    strainHash.ploidyDetermination = rec[22];
    strainHash.qcFailure = rec[23];
    strainHash.qcFailureReason = rec[24];
    strainHash.qcNotes = rec[25];
    strainHash.savedBy = rec[26];
    strainHash.siblings = rec[27];
    strainHash.mta = rec[28];
    strainHash.ceresiaeDetermination = rec[29];
    strainHash.ploidyNotes = rec[30];
    strainHash.isbBoxNumber = rec[31];
    strainHash.geographyDate = rec[32];
}

function populateSingleYADViaSearch(strainHash, rec) {
    strainHash.name = rec.yadKey;
    strainHash.alias = rec.yadAlias;
    strainHash.status = rec.yadStatus;
    strainHash.matingType = rec.yadMatingType;
    strainHash.genotype = rec.yadGenotype;
    strainHash.strainParents = rec.yadParent;
    strainHash.boxNumber = rec.yadBoxNumber;
    strainHash.dateFrozen = rec.yadDateFrozen;
    strainHash.contributor = rec.yadContributor;
    strainHash.comments = rec.yadComments;
    strainHash.position = rec.yadPosition;
    strainHash.isbBoxNumber = rec.yadIsbNumber;
    strainHash.strainSource = rec.yadSource;
}

var breakDelimiter = "<br></br>";
//var csvDelimiter = "NewL1ne";

var positionChars = "ABCDEFGHI";

//isNew implies that new can not be null and that the new position is greater than the old position
function isNewPosition(oldPosition, newPosition) {
    if (newPosition == null || newPosition == "") {
        return false;
    } else if (oldPosition == "I9" && newPosition == "A1") {
        return true;
    }
    return (newPosition > oldPosition);
}

//this function accepts a character, increments it
//by one, and returns it
function getNextPosition(oldPosition) {

    var letterToIncrement = oldPosition.substring(0, 1);
    var numberToIncrement = oldPosition.substring(1, 2);
    if (numberToIncrement == 9) {
        var indexOfLetter = positionChars.search(letterToIncrement);
        //if it's not the last letter, then return the next
        //letter in the string
        if (indexOfLetter + 1 < positionChars.length) {
            return(positionChars.charAt(indexOfLetter + 1) + "1");
        }
        //otherwise return the first letter
        else {
            return("A1");
        }
    } else {
        numberToIncrement++;
        return letterToIncrement + "" + numberToIncrement;
    }
}

function placeHolder() {
    Ext.Msg.alert("info", "Viewer window is under construction");
}


function postDudleyAnnotations(annotationUri, jsonToPost, callback) {
    Ext.Ajax.request({
        url: annotationUri,
        method: 'POST',
        params: {
            JSON: Ext.encode(jsonToPost)
        },
        success: function() {
            eventManager.fireStatusMessageEvent({ text: "LIMS AJAX Posted Successfully", level: "info" });
            callback();
        },
        failure: function() {
            Ext.Msg.alert("error", "Failed saving annotations for key:" + annotationUri);
        }
    });
}

var htmlvals = {};
var pending_changes = {};

// {{{ blur and sync event
function on_editor_blur(key)
{
    var val = replacedIllegalEntries(Ext.getCmp(key).getRawValue());
    Ext.getCmp(key).setValue(val);
}

// fired before sync: (save the value)
// c = htmleditor component
// h = html
function on_editor_sync(c, h)
{
    // make sure this text box is "saved" because the html was changed!
    if (htmlvals[c.id] != h) {
        pending_changes[c.name] = c;
    }
}

function on_editor_bsync(c, h)
{
    htmlvals[c.id] = $(c.id).value;
}


/*
 The following special characters will break extjs/jcr rest calls
 */
function replacedIllegalEntries(entry) {
    entry = entry.replace(/['"@#%&$]/g, "");
    return entry;
}

/*
 Thank you: http://snipplr.com/users/Roshambo/
 */
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function getEnterClick(id) {
    /*[
     {
     key: [Ext.EventObject.ENTER],
     fn: function() {
     Ext.ComponentMgr.get('crossingSearchButtonId').fireEvent('click');
     }
     }
     ]*/
    return new [
        {
            key: [Ext.EventObject.ENTER],
            fn: function() {
                Ext.ComponentMgr.get(id).fireEvent('click');
            }
        }
    ];
}

function pausecomp(millis)
{
    var date = new Date();
    var curDate = null;

    do {
        curDate = new Date();
    }
    while (curDate - date < millis);
}

function trim(str) {
    return str.replace(/^\s+|\s+$/g, '');
}

function getSearchLoadingWindow(dslabel) {
    return new Ext.Window({
        title: 'Loading ' + dslabel,
        width: 400,
        minWidth: 350,
        height: 150,
        modal: true,
        closeAction: 'hide',
        bodyStyle: 'padding:10px;',
        html: "Loading " + dslabel,
        bbar: new Ext.ux.StatusBar({
            id: dslabel + 'search-statusbar',
            defaultText: 'Ready'
        })
    });
}

function getSearchTextfield(fid, advancedSearchLink, hintText) {
    /*if (!hintText){
        hintText = 'Add * for wildcard search, such as TCGGA*, you can use ? for substitute, implying te?t finds test, text, ...';
    } */
    if (!advancedSearchLink) {
        advancedSearchLink = "Search"
    }
    return {
        xtype:'textfield',
        fieldLabel: advancedSearchLink,
        id: fid,
        name: fid,
        anchor:'95%',
        listeners: {
            render: function(c) {
                Ext.QuickTips.register({
                    target: c,
                    title: '',
                    text: hintText
             });
            }//render
        }//end listeners
    };//return
}

function getSearchForm(buttonid, textinputid, advancedSearchLink) {

    var yosearchtextfield = getSearchTextfield(textinputid, advancedSearchLink,  'Use * for wildcard search, like TCGGA*, add spaces between values such as WINE GFP ..., results in an AND condition. Use WINE OR GFP ... for OR logic, sorry no mixing');
    var yoSearchForm = new Ext.form.FormPanel({
        id: 'SearchForm_' + buttonid,
        method: 'POST',
        autoHeight: true,
        buttonAlign: 'center',
        title: '',
        keys: [
            {
                key: [Ext.EventObject.ENTER],
                fn: function() {
                    Ext.ComponentMgr.get(buttonid).fireEvent('click');
                }
            }
        ],
        items: [
            {
                layout:'column',
                items:[
                    {
                        columnWidth:.75,
                        border: false,
                        layout: 'form',
                        items: [
                            yosearchtextfield
                        ]
                    },
                    {
                        layout: 'form',
                        border: false,
                        items: [
                            {
                                xtype: 'button',
                                fieldAlign: 'center',
                                text: '&nbsp;&nbsp;Search&nbsp;&nbsp;',
                                id: buttonid
                            }
                        ]
                    }
                ]
            }
        ]
    });
    return yoSearchForm;
}

function launchGBrowse(){
var gbchrStore = new Ext.data.SimpleStore({
    fields: ['key', 'value'],
    data :  [
        ['01', '01'],
        ['02', '02'],
        ['03', '03'],
        ['04', '04'],
        ['05', '05'],
        ['06', '06'],
        ['07', '07'],
        ['08', '08'],
        ['09', '09'],
        ['10', '10'],
        ['11', '11'],
        ['12', '12'],
        ['13', '13'],
        ['14', '14'],
        ['15', '15'],
        ['16', '16'],
        ['mt', 'mt']
    ]
});
 var gbfields = new Ext.form.FieldSet({
                items: [
                new Ext.form.ComboBox({
            store: gbchrStore,
            id: 'gbchrId',
            displayField:'value',
            valueField:'key',
            typeAhead: true,
            mode: 'local',
            width: 150,
            triggerAction: 'all',
            fieldLabel: 'Chromosome',
            value:"1",
            forceSelection:true,
            selectOnFocus:true
         }),
                new Ext.form.TextField({
                            id: "gbpositionId",
                            fieldLabel: 'Position range',
                            value: "10000..50000",
                            width: 150,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Starting position/range to begin exploring genome, must be in format of pos1..pos2'
                                    });
                                }
                            }
                 }),
                 new Ext.form.TextField({
                            id: "gbgeneId",
                            fieldLabel: 'Gene',
                            value: "",
                            width: 150,
                            allowBlank: false,
                            listeners: {
                                render: function(c) {
                                    Ext.QuickTips.register({
                                        target: c,
                                        title: '',
                                        text: 'Explore GBrowse starting with Gene name, this supersedes range positions'
                                    });
                                }
                            }
                 })]
            });
    new Ext.Window({
                title: 'GBrowse - Select chromosome and start/end positions',
                width: 400,
                height: 200,
                autoScroll: true,
                modal: true,
                bodyStyle: 'padding:2px;',
                items: [   gbfields],
                buttons: [
                    {
                        text: 'Explore',
                        handler: function() {
                             var geneName =  Ext.getCmp("gbgeneId").getValue();
                             var gurl = "http://gbrowse.systemsbiology.net/cgi-bin/gb2/gbrowse/yeast/?name=chr" + Ext.getCmp("gbchrId").getValue() + ":" + Ext.getCmp("gbpositionId").getValue();
                             if (geneName != null && geneName.length > 1){
                                gurl = "http://gbrowse.systemsbiology.net/cgi-bin/gb2/gbrowse/yeast/?name=" + geneName;
                             }
                             window.open(gurl, "GBrowse", "height=680, width=880");
                        }
                    }
                ],
                layout: 'fit'
            }).show();
}
